package com.house365.core.util.intent;

import java.io.File;

import com.house365.core.util.FileUtil;
import com.house365.core.util.TextUtil;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.provider.MediaStore;

public class IntentHelper {
	
	public static final String IMAGE_UNSPECIFIED = "image/*"; // 图片类型
	public static Intent getSmsIntent(String mobile,String content){
		String smsUri="smsto:";
		if(mobile != null){
			smsUri +=mobile;
		}
		Uri smsToUri = Uri.parse(smsUri);  
	    Intent mIntent = new Intent(android.content.Intent.ACTION_SENDTO, smsToUri);  
	    if(content!= null){
	    	mIntent.putExtra("sms_body", content);  
	    }
	    return mIntent;
	}
	
	public static Intent getCallIntent(String mobile){
		 
		String callUri="tel:";
		if(mobile != null){
			callUri +=TextUtil.filterTel(mobile);
		}
		Uri callToUri = Uri.parse(callUri);  
	    Intent mIntent = new Intent(Intent.ACTION_CALL, callToUri);  
	    return mIntent;
	}
	
	public static Intent getCameraIntent(){
		Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);  
		return i;
	}
	//拍照
	public static Intent getCameraIntent(File tempfile){
		Intent shootIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
		shootIntent.putExtra(MediaStore.EXTRA_OUTPUT,
				Uri.fromFile(tempfile));
		return shootIntent;
	}
	//相册
	public static Intent getAlbumIntent(){
		Intent intentAlbum = new Intent(Intent.ACTION_GET_CONTENT, null);
		intentAlbum.setDataAndType(
				MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
				IMAGE_UNSPECIFIED);
		 return intentAlbum;
	}
	//裁剪
	public static Intent startPhotoZoom(Uri input, Uri output) {
		Intent intent = new Intent("com.android.camera.action.CROP");
		intent.setDataAndType(input, IMAGE_UNSPECIFIED);
		intent.putExtra("crop", "true");
		intent.putExtra("output", output);
		return intent;
	}
	//打开文件
	public static void openFileByType(Context context, File f) {
		Intent intent = new Intent();
		intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		intent.setAction(android.content.Intent.ACTION_VIEW);
		intent.addCategory(Intent.CATEGORY_DEFAULT);
		String type = FileUtil.getMIMEType(f);
		intent.setDataAndType(Uri.fromFile(f), type);
		context.startActivity(intent);
	}
	//获取文件MIME
	public static Intent getMIMEIntent(File f){
		Intent intent = new Intent();
		intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		intent.setAction(android.content.Intent.ACTION_VIEW);
		String type = FileUtil.getMIMEType(f);
		intent.setDataAndType(Uri.fromFile(f), type);
		return intent;
	}
}
